﻿<cfsilent>
	<cfsetting requesttimeout="90" />
	<cfscript>
		
		event.setArg("pageTitle", "网上选课");
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		propAdvice = getProperty("serviceFactory").getBean("turnPropertyAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");

		studentPropAdvice = getProperty("serviceFactory").getBean("studentPropertyAdvice");

		termId = event.getArg("TermID");

		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		/* 学籍相关信息 */
		//studentId = sessionAdvice.getAutherUserID();
		//studentClassId = sessionAdvice.getUserProp("studentClass");
		studentSubjectId = sessionAdvice.getUserProp("studentSubject");
		//studentDirId = sessionAdvice.getUserProp("studentSubDir");
		studentGrade = sessionAdvice.getUserProp("studentGrade");
		studentDepartment = sessionAdvice.getUserProp("studentDepartment");
		studentProps = sessionAdvice.getUserProp("studentProps");

		studentPropAdvice.parseProperty( studentProps );
		
		currentTab = event.getArg("TabID", "labWelcome");
		
		today = datetimeAdvice.getCurrentDateString();
		

		/* 总体安排 */
		
		sql = "SELECT 
					turn, date_start, date_end, time_start, time_end,
					grade_allowed, institute_allowed, subject_allowed 
				FROM 
					t_choose_turn c 
				WHERE 
					subStr(c.turn_prop,1,1) = '1' AND ct = '1' 
				ORDER BY 
					c.ct ";
		queryObj = new query( datasource=application.dnsSlave );
		rs_all = queryObj.execute( sql=sql ).getResult();

		/* 检查当前活动的选课轮次 */
		sql = "SELECT 
					turn,date_start,date_end,time_start,time_end,
					grade_allowed,institute_allowed,
					turn_prop,ct,subject_allowed 
				FROM 
					t_choose_turn 
				WHERE 
					substr(turn_prop,1,1) = '1' 
					AND 
					(date_start < :today or date_start = :today ) 
					AND
					(date_end > :today or date_end = :today) 
				ORDER BY 
					ct ";
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="today", value=today, cfsqltype="cf_sql_varchar" );
		rs_turn = queryObj.execute( sql=sql ).getResult();
		
		targetArgs = structNew();
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i><cfoutput>#academicYear#</cfoutput>学年 <cfoutput>#dictAdvice.getTerm(academicTerm)#</cfoutput> - 网上选课
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="welcome">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labWelcome">class="active"</cfif> id="labWelcome" tabTarget="Welcome">网上选课安排</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					
					// -->
					//]]>
				</script>
				<div id="Welcome" class="tabContent">

					<cfif rs_turn.recordCount GT 0>

						<cfset currentTime = TimeFormat(now(), "HHMM") />
						
						<div class="noticeBlock">
							<h3>选课时间段安排</h3>
							<p>
								<cfoutput>#rs_turn.turn#</cfoutput>, 
								本轮选课从 
								<em><cfoutput>#datetimeAdvice.formatDateString(rs_turn.date_start)#</cfoutput></em>
								至
								<em><cfoutput>#datetimeAdvice.formatDateString(rs_turn.date_end)#</cfoutput></em>
								
								<cfif rs_turn.time_start eq "0001" and rs_turn.time_end eq "2359">
										全天
									<cfelse>
										每天
										<em><cfoutput>#datetimeAdvice.formatTimeString(rs_turn.time_start, 'HH:MI')#</cfoutput> ~ <cfoutput>#datetimeAdvice.formatTimeString(rs_turn.time_end, 'HH:MI')#</cfoutput></em>
								</cfif>
							</p>
							<p>
								选课年级: 
								<cfif rs_turn.grade_allowed eq "ALL">
									全部
									<cfelse>
									<em><cfoutput>#replace(rs_turn.grade_allowed, ",", " | ", "all")#</cfoutput></em>
								</cfif>
							</p>
							<p>
								
								<cfif rs_turn.institute_allowed eq "ALL">
                                		全部学院
                                    <cfelseif rs_turn.institute_allowed neq '-'>
                                    <cfscript>
                                    	sql = "SELECT 
													institute_short 
												FROM 
													t_institute 
												WHERE 
													 institute_id IN (:insIds) ";
										queryObj = new query( datasource=application.dnsSlave);
										queryObj.addParam( name="insIds", value=rs_turn.institute_allowed, cfsqltype="cf_sql_char", list=true );
										rs_insSelect = queryObj.execute( sql=sql ).getResult();
                                    </cfscript>
                                    
									<cfoutput>选课学院: #valueList(rs_insSelect.institute_short, " | ")#</cfoutput>
								</cfif>
							</p>
							<p>
                                <cfif rs_turn.subject_allowed eq "ALL">
										全部专业
									<cfelseif rs_turn.subject_allowed neq '-'>
                                    <cfscript>
                                    	sql = "SELECT 
													s.sbj_name   
												FROM 
													t_subject s 
												WHERE 
													s.sbj_id IN (:subIds) ";
										queryObj = new query( datasource=application.dnsSlave);
										queryObj.addParam( name="subIds", value=rs_turn.subject_allowed, cfsqltype="cf_sql_char", list=true );
										rs_subSelect = queryObj.execute( sql=sql ).getResult();
                                    </cfscript>
									<cfoutput>选课专业: #valueList(rs_subSelect.sbj_name, " | ")#</cfoutput>
								</cfif>
                                
							</p>
							<hr/>
						</div>
						
						<!--- 判断选课时段 --->
						<cfif ( rs_turn.time_start lte currentTime and currentTime lte rs_turn.time_end )>
						
								<!--- 判断是否在允许范围内 --->
								<cfif 
									( rs_turn.grade_allowed eq "ALL" or listFind(rs_turn.grade_allowed, studentGrade, ",") ) 
									and 
									( rs_turn.institute_allowed eq "ALL" or listFind(rs_turn.institute_allowed, studentDepartment, ",") or (rs_turn.subject_allowed neq '-' and listFind(rs_turn.subject_allowed, studentSubjectId)) )>
									<!--- 学院和年级都在允许的范围内 --->
									
									<cfset structInsert(targetArgs, "CT", rs_turn.ct, true) />
									
									<!--- 生成选课菜单 --->
									<cfset propAdvice.parseProperty( rs_turn.turn_prop ) />
									
									<cfset typeArray = [] />

									<!--- 计划课程 --->
									<cfif propAdvice.getProgramTask()><cfset arrayAppend(typeArray, "P") /></cfif>
									<!--- 全校通选课 --->
									<!---<cfif propAdvice.getCommonTask()><cfset arrayAppend(typeArray, "C") /></cfif>--->
									<!--- 体育项目 --->
									<!---<cfif propAdvice.getSport()><cfset arrayAppend(typeArray, "T") /></cfif>
									<!--- 重修课 --->
									<cfif propAdvice.getRetaking()><cfset arrayAppend(typeArray, "R") /></cfif>
									<!--- 低年级补修 --->
									<cfif propAdvice.getFixUp()><cfset arrayAppend(typeArray, "F") /></cfif>
									<!--- 辅修选课 --->
                                    <cfif propAdvice.getAssist() and studentPropAdvice.getAssist()><cfset arrayAppend(typeArray, "A") /></cfif>
                                    <!--- 双学位选课 --->
                                    <cfif propAdvice.getSecondary() and studentPropAdvice.getSecondary()><cfset arrayAppend(typeArray, "S") /></cfif>
                                    <!--- 提前毕业选课 --->
                                    <cfif propAdvice.getEarlyGraduate() and studentPropAdvice.getEarlyGraduate()><cfset arrayAppend(typeArray, "E") /></cfif>--->
									
									<cfif arrayLen(typeArray)>
										<div class="clearfix">
											<ul class="UIDashBoard">
												<cfset i = 0 />
												<cfloop array="#typeArray#" index="typper">
													<cfset i++ />
													<li class="col2 <cfif i mod 2 eq 0>last</cfif>">
														<div class="board hasPic">
															<cfswitch expression="#typper#">
																<cfcase value="P">
																<a href="<cfoutput>#buildURL('programTask', targetArgs)#</cfoutput>">
																<div class="pic"> <span class="icon64x64 tasktype<cfoutput>#typper#</cfoutput>"></span> </div>
																<div class="content">
																	<h5>选修课程</h5>
																	<p class="describ">学院本学期开设的所有选修课程.</p>
																	<p class="desc">（如果不明确，请找班主任或任课教师）</p>
																</div>
																</a>
																</cfcase>
																<!---<cfcase value="C">
																<a href="<cfoutput>#buildURL('commonTask', targetArgs)#</cfoutput>">
																<div class="pic"> <span class="icon64x64 tasktype<cfoutput>#typper#</cfoutput>"></span> </div>
																<div class="content">
																	<h5>全校通选课</h5>
																	<p class="describ">全校通选课引导学生广泛涉猎不同学科领域, 获取到更多的课程知识, 拓宽知识面, 开拓视野.</p>
																	<p class="desc">通选课修读无任何限制</p>
																</div>
																</a>
																</cfcase>--->
																<!---<cfcase value="T">
																<a href="<cfoutput>#buildURL('sportTask', targetArgs)#</cfoutput>">
																<div class="pic"> <span class="icon64x64 tasktype<cfoutput>#typper#</cfoutput>"></span> </div>
																<div class="content">
																	<h5>体育项目</h5>
																	<p class="describ">您可以在这里根据个人喜好, 选择体育项目并完成体育必修课程学分</p>
																	<p class="desc">体育项目无任何强制项目选择要求, 不可重复修读已通过课程</p>
																</div>
																</a>
																</cfcase>--->
																<cfcase value="R">
																<a href="<cfoutput>#buildURL('retakeTask', targetArgs)#</cfoutput>">
																<div class="pic"> <span class="icon64x64 tasktype<cfoutput>#typper#</cfoutput>"></span> </div>
																<div class="content">
																	<h5>重新学习</h5>
																	<p class="describ">补考不及格者可跟班重新修读课程. 已合格的课程, 若对其成绩不满意者, 也可申请重新选课修读, 成绩按高分记.</p>
																	<p class="desc">受限于专业培养方案、仅可选低年级课程</p>
																</div>
																</a>
																</cfcase>
																<!---<cfcase value="F">
																<a href="<cfoutput>#buildURL('fixupTask', targetArgs)#</cfoutput>">
																<div class="pic"> <span class="icon64x64 tasktype<cfoutput>#typper#</cfoutput>"></span> </div>
																<div class="content">
																	<h5>补选低年级课程</h5>
																	<p class="describ">专升本、转专业等学籍异动学生可跟班修读培养方案的低年级课程. 若之前学期存在漏选课的学生, 也可申请跟班修读.</p>
																	<p class="desc">受限于专业培养方案、仅可选低年级课程</p>
																</div>
																</a>
																</cfcase>--->
																<cfcase value="S">
																	<a href="<cfoutput>#buildURL('secTask', targetArgs)#</cfoutput>">
																	<div class="pic"> <span class="icon64x64 tasktype<cfoutput>#typper#</cfoutput>"></span> </div>
																	<div class="content">
																		<h5>双学位课程</h5>
																		<p class="describ">你已经具有双学位学籍，你可以修订培养方案中标记为双学位的课程，这些课程的成绩最终会纳入双学位学位审核.</p>
																		<p class="desc">建议选课由易到难。</p>
																	</div>
																	</a>
																</cfcase>
																<cfcase value="A">
																	<a href="<cfoutput>#buildURL('assistTask', targetArgs)#</cfoutput>">
																	<div class="pic"> <span class="icon64x64 tasktype<cfoutput>#typper#</cfoutput>"></span> </div>
																	<div class="content">
																		<h5>辅修课程</h5>
																		<p class="describ">你已经具有辅修学籍，所列出的课程是你修读的第二专业所在的培养方案中所有被标记为辅修的课程。</p>
																		<p class="desc">选择辅修课程是建议由易到难</p>
																	</div>
																	</a>
																</cfcase>
																<cfcase value="E">
																	<a href="<cfoutput>#buildURL('earlyTask', targetArgs)#</cfoutput>">
																	<div class="pic"> <span class="icon64x64 tasktype<cfoutput>#typper#</cfoutput>"></span> </div>
																	<div class="content">
																		<h5>提前毕业选课</h5>
																		<p class="describ">你已经具有提前毕业资格，所列出的课程是你修读的专业所在的培养方案中所有高学期的课程。</p>
																		<p class="desc">选择高年级课程建议由易到难</p>
																	</div>
																	</a>
																</cfcase>
															</cfswitch>
														</div>
													</li>
												</cfloop>
											</ul>
										</div>
										<cfelse>
										<div class="systemNotice">
											<p>没有适合您的选课模式</p>
										</div>
									</cfif>
									
										
										
								<cfelse>
									<div class="systemNotice">
										<p>当前不是您的选课时间</p>
									</div>
								</cfif>
						
							<cfelse>
								<div class="systemNotice">
									<p>当前不是选课时间</p>
								</div>
						</cfif>
						
					</cfif>
					
					<cfif rs_turn.recordCount EQ 0 >
						
						<div class="systemNotice">
							<h3><span class="img icon16x16 info"></span>现在不是选课时间</h3>
							<cfif rs_all.recordCount GT 0>
								<ol>
                                    <cfloop query="rs_all">
										<li class="showTime">
											<strong><cfoutput>#rs_all.turn#</cfoutput></strong>
											时间段安排从
											<em><cfoutput>#datetimeAdvice.formatDateString(rs_all.date_start)#</cfoutput></em>
											至
											<em><cfoutput>#datetimeAdvice.formatDateString(rs_all.date_end)#</cfoutput></em>
											每天
											<i><cfoutput>#datetimeAdvice.formatTimeString(rs_all.time_start, 'HH:MI')#</cfoutput> ~ <cfoutput>#datetimeAdvice.formatTimeString(rs_all.time_end, 'HH:MI')#</cfoutput></i>
											<br/>
											选课年级: 
												<cfif rs_all.grade_allowed eq "ALL">
													全部
												<cfelse>
													<cfoutput>#replace(rs_all.grade_allowed, ",", ", ", "all")#</cfoutput>
												</cfif>
											 
												<cfif rs_all.institute_allowed eq "ALL">
													全部学院
												<cfelseif rs_all.institute_allowed neq '-'>
                                                	<cfscript>
														sql = "SELECT 
																	s.institute_short   
																FROM 
																	t_institute s 
																WHERE 
																	s.institute_id IN (:insIds) ";
														queryObj = new query( datasource=application.dnsSlave);
														queryObj.addParam( name="insIds", value=rs_all.institute_allowed, cfsqltype="cf_sql_char",list=true );
														rs_insSelect = queryObj.execute( sql=sql ).getResult();
													</cfscript>
													选课学院：<cfoutput>#valueList(rs_insSelect.institute_short, ", ")#</cfoutput>
												</cfif>
											
												<cfif rs_all.subject_allowed eq "ALL">
													全部专业
												<cfelseif rs_all.subject_allowed neq '-'>
                                                	<cfscript>
														sql = "SELECT 
																	s.sbj_name  
																FROM 
																	t_subject s 
																WHERE 
																	s.sbj_id IN ( :subIds ) ";
														queryObj = new query( datasource=application.dnsSlave);
														queryObj.addParam( name="subIds", value=rs_all.subject_allowed, cfsqltype="cf_sql_varchar", list=true );
														rs_subSelect = queryObj.execute( sql=sql ).getResult();
													</cfscript>
                                                   
													选课专业: <cfoutput>#valueList(rs_subSelect.sbj_name, " | ")#</cfoutput>
												</cfif>
										</li>
									</cfloop>
								</ol>
							</cfif>
						</div>
						
					</cfif>

				
				</div>
			</div>
		</li>
	</ul>
</div>